<?php 
/**
 *   Joomdiet - administrator/components/views/default/tmpl/default.php
 *   Author: Juan Dapena Paz (juan@bittingbits.com)
 *   Copyright (C) 2010 Bitting Bits S.L.
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
defined('_JEXEC') or die('Restricted access');
 JHTML::_( 'behavior.modal' ); ?>

<?php jimport('joomla.html.pane'); ?>
<?php JHTML::_('behavior.calendar'); ?>
<?php JHTML::_('behavior.formvalidation'); ?>

<script type="text/javascript">
  // thanks to epsi for pointing me in the right direction!
  // http://forum.joomla.org/viewtopic.php?f=304&t=419618
 
  // "extend" base validator
  var myFormValidator = JFormValidator.extend({});
  // override core behavior
  function submitbutton( pressbutton )
  {
    if( pressbutton == 'cancel' )
    {
      submitform( pressbutton );
      return true;
    }
    var form = document.adminForm;
    var validator = new myFormValidator();
    if( validator.isValid( form ) )
    {
      submitform( pressbutton );
    }
    else
    {
      alert( 'Please correct any errors before submission.' );
    }
  }
  // our validation script
  function doValidate( f )
  {
    if( document.formvalidator.isValid( f ) )
    {
      return true;
    }
    return false;
  }
</script>

<style type="text/css">
  .invalid { border: 1px solid red; }
</style>

<form action="index.php" method="post" name="adminForm" id="adminForm" enctype="multipart/form-data" class="form-validate" onSubmit="return doValidate(this);">
<input type="hidden" name="check" value="post" />
<div id="col100">
    <table cellspacing="0" cellpadding="0" border="0" width="100%">
        <tr><td valign="top">
        <fieldset class="adminform">
            <legend><?php echo JText::_('COM_BBITSSD_EDIT_LEGEND'); ?></legend>
            <input type="hidden" name="item_id" id="item_id" value="<?php echo $this->row->id; ?>"/>

            
            <table class="adminform">
                        <tr>
            	<td><?php echo JText::_('ID'); ?></td>
            	<td><?php echo $this->row->id; ?></td>
            </tr>
            	<tr>
            	<td><?php echo JText::_('COUNTRY'); ?></td>
            		<td>
  
  <?php
if(isset($this->row->country)):
  $default = $this->row->country;
else:
	$default = '';
endif;
 
  ## Initialize array to store dropdown options ##
  $options = array();
 
  foreach($this->countries as $g) :
    ## Create $value ##
		
    $options[] = JHTML::_('select.option', $g->id, $g->title);
  endforeach;
 
  ## Create <select name="month" class="inputbox"></select> ##
  $dropdown = JHTML::_('select.genericlist', $options, 'country_id', 'class="inputbox"', 'value', 'text', $default);
 
  ## Output created <select> list ##
  echo $dropdown;

  ?>	
            		</td>
            	</tr>

            	
<tr>
            	<td><?php echo JText::_('TYPE'); ?></td>
            		<td>

  
  
  <?php
if(isset($this->row->type)):
  $default = $this->row->type;
else:
	$default = '';
endif;
 
  ## Initialize array to store dropdown options ##
  $options = array();
 
  foreach($this->types as $g) :
    ## Create $value ##
		
    $options[] = JHTML::_('select.option', $g->id, $g->title);
  endforeach;
 
  ## Create <select name="month" class="inputbox"></select> ##
  $dropdown = JHTML::_('select.genericlist', $options, 'type_id', 'class="inputbox"', 'value', 'text', $default);
 
  ## Output created <select> list ##
  echo $dropdown;

  ?>
            		
            		</td>
</tr>
            	
            	
            	
            	
                <tr>
                    <td width="100" align="right" class="key">
                        <label for="country_name"><?php echo JText::_('COM_BBITSSD_TITLEITEM'); ?> *</label>
                    </td>
                    <td>
                        <input class="text_area required" type="text" name="item_title" id="item_title" size="42" maxlength="140" value="<?php echo $this->row->title;?>" />
                    </td>
                </tr>
                
               <?php if($this->row->image!=''): ?> 
                <tr>
                	<td><?php echo JText::_('COM_BBITSSD_LOGOFILEIM'); ?></td>
                	<td>
                	
                	
                		<a class="modal" href="<?php echo JURI::base(); ?>/components/com_bbitsd/assets/uploads/<?php echo $this->row->image;?>">
                		<img src="<?php echo JURI::base(); ?>/components/com_bbitsd/assets/uploads/<?php echo $this->row->image;?>" width="100px"/>
                		</a>					<br />
					<input type="checkbox" name="delete_im" value="1"> <?php echo JText::_('COM_BBITSSD_DELCURRIMAGE'); ?>

                		
                	</td>
                </tr>
                
                
                <?php endif;?>
                
                <tr>
                	<td><?php echo JText::_('COM_BBITSSD_LOGOFILE'); ?></td>
                	<td>
                		<input class="input_box" type="file" id="uploadFile" name="uploadFile"/>
                	</td>
                </tr>
                
                 <tr>
                	<td><?php echo JText::_('STATE'); ?></td>
                	<td>
                		<select name="published" id="published">
                			<option value="1" <?php if($this->row->published==1): echo 'selected="selected"'; endif;?>><?php echo JText::_('ENABLED'); ?></option>
                			<option value="0" <?php if($this->row->published==0): echo 'selected="selected"'; endif; ?>><?php echo JText::_('DISABLED'); ?></option>
                		</select>
                	</td>
                </tr>
                
                
                <tr>
                	<td><?php echo JText::_('COM_BBITSSD_DATEADDED'); ?></td>
                	<td>
                		<input id="checked_out_time" name="checked_out_time" size="20" type="text" class="required" value="<?php echo $this->row->checked_out_time;?>"/>
                		<img class="calendar" onclick="return showCalendar('checked_out_time', '%Y-%m-%d %H:%M:%S');" src="templates/system/images/calendar.png" alt="calendar" />
                	</td>
                </tr>
                
                
                <tr>
                	<td><?php echo JText::_('COM_BBITSSD_DIRECTION'); ?></td>
                	<td>
                		<input class="text_area" size="42" type="text" id="direction" name="direction" value="<?php echo $this->row->direction;?>" />
                	</td>
                </tr>
                
                <tr>
                	<td><?php echo JText::_('COM_BBITSSD_PHONE'); ?></td>
                	<td>
                		<input class="text_area" size="42" type="text" id="phone" name="phone" value="<?php echo $this->row->phone;?>" />
                	</td>
                </tr>
                
                <tr>
                	<td><?php echo JText::_('COM_BBITSSD_FAX'); ?></td>
                	<td>
                		<input class="text_area" size="42" type="text" id="fax" name="fax" value="<?php echo $this->row->fax;?>" />
                	
                	</td>
                </tr>
                
                <tr>
                	<td><?php echo JText::_('COM_BBITSSD_EMAIL'); ?></td>
                	<td>
                		<input class="text_area" size="42" type="text" id="email" name="email" value="<?php echo $this->row->email;?>" />
                	
                	</td>
                </tr>
                
                <tr>
                	<td><?php echo JText::_('COM_BBITSSD_URL'); ?></td>
                	<td>
                		<input class="text_area" size="42" type="text" id="url" name="url" value="<?php echo $this->row->url;?>" />
                	
                	</td>
                </tr>
                
                
                <tr>
                	<td><?php echo JText::_('COM_BBITSSD_DESC'); ?></td>
                	<td>
                	<?php
					$editor =& JFactory::getEditor();
					echo $editor->display('description', $this->row->description, '550', '300', '60', '20', false);
				?>
                	
                	</td>
                </tr>
                

			
              </table>
        </fieldset>
        </td>
        
       </tr>
       </table>
</div>

<input type="hidden" name="current_image" value="<?php echo $this->row->image;?>" />
<input type="hidden" name="option" value="com_bbitsd" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="controller" value="items" />

</form>

